import { Injectable } from '@angular/core';
import {Observable} from "rxjs/Observable";
import {DamAPI} from "../../peach-constants";
import {MsgResult} from "../../../../models/msg-result";
import {RequestUtil} from "../../../../util/request-util";
import {API} from "../../../../constants/constants";
@Injectable()
export class RealTimeService {

  constructor(
    private requestUtil: RequestUtil
  ) { }

  getMapSiteData(pointType):Observable<MsgResult>{
    let params = "format=json&pointType="+pointType;
    let SiteUrl = DamAPI.mapSiteInfo;
    if(pointType == "raiseDustNewSite"){
      SiteUrl = DamAPI.mapDustSiteInfo;
    }
    return this.requestUtil.get(SiteUrl,params);
  }
  getMapSiteDetail(siteType,siteCode):Observable<MsgResult>{
    let params = "format=json&siteType="+siteType+"&siteCode="+siteCode;
    return this.requestUtil.get(DamAPI.mapSiteDetail,params);
  }
  getMapSiteDetailFive(siteType,siteCode):Observable<MsgResult>{
    let params = "format=json&siteType="+siteType+"&siteCode="+siteCode;
    return this.requestUtil.get(DamAPI.mapSiteDetailFive,params);
  }
  getHotHeatData(searchDate):Observable<MsgResult>{
    let params = "format=json&searchDate="+searchDate+"&siteTypeCode=001,002,003,004";
    return this.requestUtil.get(DamAPI.trackHotHeatData,params);
  }
  getUserSite():Observable<MsgResult>{
    return this.requestUtil.get(DamAPI.getUserSite);
  }
  getMapSiteFence():Observable<any>{
    return this.requestUtil.get(DamAPI.getMapSiteFence);
  }
  getMapSiteSearch(siteName,siteTypeList ):Observable<any>{
    let params = "format=json&siteName="+siteName+"&siteTypeList="+siteTypeList;
    return this.requestUtil.post(DamAPI.getMapSiteSearch,params);
  }
  getRealAQIData():Observable<MsgResult>{
    let params = "format=json";
    return this.requestUtil.get(DamAPI.getRealAQIData,params);
  }
  getCityRanking(order):Observable<MsgResult>{
    let params = "order="+order;
    return this.requestUtil.get(DamAPI.cityRanking,params);
  }
  getHistoryAlertData(siteCode,dataNum):Observable<MsgResult>{
    let params = "format=json&siteCode="+siteCode+"&number="+dataNum;
    return this.requestUtil.get(DamAPI.historyAlertData,params);
  }
  getCarRealPoint(deviceType):Observable<MsgResult>{
    let params = "deviceType="+deviceType;
    return this.requestUtil.get(DamAPI.carRealPoint,params);
  }

  /**
   * 修改报警信息状态
   */
  putWarnSiteStatus(contentId):Observable<any> {
    return this.requestUtil.put(DamAPI.putWarnSiteStatus + '/' +contentId+ '?format=json');
  }
  /**
   * 获取框选区域的信息
   */
  getSelectAreaPoint(obj):Observable<MsgResult>{
    let params = "lngSets="+obj.lngSets+"&latSets="+obj.latSets+"&pointTypes="+obj.pointType;
    return this.requestUtil.get(DamAPI.selectAreaData,params);
  }
  /**
   * 获取账户名
   */
  getAccountName():Observable<MsgResult>{
    return this.requestUtil.get(API.getOnlineAccountName);
  }
}
